package com.snailvr.tv.ui.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.snail.readyvr.R;
import com.snail.readyvr.util.SPUtils;
import com.snailvr.tv.Definition;
import com.snailvr.tv.ui.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/11/18.
 */

public class PlayModeActivity extends BaseActivity {
    @BindView(R.id.radio_group_mode)
    RadioGroup mRadioGroup;

    @BindView(R.id.radio_2d)
    RadioButton mRadioButton2d;

    @BindView(R.id.radio_button_180_2d)
    RadioButton mRadioButton1802D;
    @BindView(R.id.radio_button_180_3d_sbs)
    RadioButton mRadioButton1803dsbs;
    @BindView(R.id.radio_button_180_3d_ud)
    RadioButton mRadioButton1803dud;

    @BindView(R.id.radio_button_360_2d)
    RadioButton mRadioButton3602d;
    @BindView(R.id.radio_button_360_3d_sbs)
    RadioButton mRadioButton3603dsbs;
    @BindView(R.id.radio_button_360_3d_ud)
    RadioButton mRadioButton3603dud;

    private  int mPlayMode;
    private Drawable mCheckedImg;


    @Override
    protected void initVariables() {
        mPlayMode = (int)SPUtils.get(this,Definition.KEY_PROJECTION, Definition.TYPE_180_3D_Left_Right);
        mCheckedImg = getResources().getDrawable(R.drawable.select);

    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_play_mode);
        ButterKnife.bind(this);

        switch (mPlayMode) {
            case Definition.TYPE_2D:
                mRadioGroup.check(R.id.radio_2d);
                mRadioButton2d.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                break;
            case Definition.TYPE_180_2D:
                mRadioGroup.check(R.id.radio_button_180_2d);
                mRadioButton1802D.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                break;
            case Definition.TYPE_180_3D_Left_Right:
                mRadioGroup.check(R.id.radio_button_180_3d_sbs);
                mRadioButton1803dsbs.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                break;
            case Definition.TYPE_180_3D_Up_Down:
                mRadioGroup.check(R.id.radio_button_180_3d_ud);
                mRadioButton1803dud.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                break;
            case Definition.TYPE_360_2D:
                mRadioGroup.check(R.id.radio_button_360_2d);
                mRadioButton3602d.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                break;
            case Definition.TYPE_360_3D_Left_Right:
                mRadioGroup.check(R.id.radio_button_360_3d_sbs);
                mRadioButton3603dsbs.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                break;
            case Definition.TYPE_360_3D_Up_Down:
                mRadioGroup.check(R.id.radio_button_180_3d_ud);
                mRadioButton3603dud.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                break;
            default:
                mRadioGroup.check(R.id.radio_button_360_2d);
                break;
        }

        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radio_2d:
                        mPlayMode = Definition.TYPE_2D;
                        mRadioButton2d.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                        break;
                    case R.id.radio_button_180_2d:
                        mPlayMode = Definition.TYPE_180_2D;
                        mRadioButton1802D.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                        break;
                    case R.id.radio_button_180_3d_sbs:
                        mPlayMode = Definition.TYPE_180_3D_Left_Right;
                        mRadioButton1803dsbs.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                        break;
                    case R.id.radio_button_180_3d_ud:
                        mPlayMode = Definition.TYPE_360_3D_Up_Down;
                        mRadioButton1803dud.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                        break;
                    case R.id.radio_button_360_2d:
                        mPlayMode = Definition.TYPE_360_2D;
                        mRadioButton3602d.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                        break;
                    case R.id.radio_button_360_3d_sbs:
                        mPlayMode = Definition.TYPE_360_3D_Left_Right;
                        mRadioButton3603dsbs.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);

                        break;
                    case R.id.radio_button_360_3d_ud:
                        mPlayMode = Definition.TYPE_360_3D_Up_Down;
                        mRadioButton3603dud.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                        break;
                    default:
                        mPlayMode = Definition.TYPE_360_2D;
                        mRadioButton3602d.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckedImg,null);
                        break;

                }
                SPUtils.put(PlayModeActivity.this,Definition.KEY_PROJECTION,mPlayMode);
                PlayModeActivity.this.finish();
            }
        });
    }

    @Override
    protected void loadData() {

    }

    @OnClick(R.id.layout_root)
    public void onClose() {
        this.finish();
    }
}
